home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
016a
/
combi030.zip
/
CMB_DEMO.C
next >
Wrap
C/C++ Source or Header
|
1991-10-26
|
5KB
|
143 lines
/* COMBI-Disk demonstration/test program
by Vadim V. Vlasov, Moscow, 1991.
Usage:
cmb_demo [d:]
where "d" is a drive letter.
The program works as following. It opens 3 files for stream output
and 3 files through handle. Then writes a text to 1st file(s),
then to 2nd one and 3rd one. Then again writes to 1st file,
closes 3rd and deletes 3rd. And at last it writes again into 2nd
file. As a result 4 files are produced which occupy clusters
not contiguously but rather mixed with other files. Moreover
a gap due to 3d file (which is deleted) is produced. See the
disk usage map for these files! Nevertheless, COMBI-Disk manages
memory usage correctly. You may run this program first for hard disk
(use e.g. "c:" parameter) and then for COMBI-Disk's RAM disk.
After that's done just compare the produced files for the two
drives. They should be identical.
You may wish to change 'repetition' constant to increase files'
sizes thus contracting space used for cache and see that if
some space (larger than your hard disk's track size) is left on
RAM disk the cache is working.
You may also interrupt (via CTRL-BREAK) this program after the
prompt "This is a second attempt... press a key...". Then the
3rd file will not be deleted and you may see its contents.
*/
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define repetition 20
main(int argc, char *argv[])
{
FILE *f1,*f2,*f3; /* for 3 streams */
int fh1,fh2,fh3; /* for 3 files opened with handle */
int i,len;
char *fname, *prompt="\npress a key...";
char *trouble="\nCan't open file!?\n";
char *text1="This text is written to file #1...\n";
char *text2="This text is written to file #2...\nFile #1 is still open.\n";
char *text3="This text is written to file #3...\nFiles #1 & #2 open.\n";
char *text4="This is second attempt to write into file #1...\nFiles #2 & #3 open.\n";
char *text5="Now we write again into file #1...\nSo far file #3 is deleted.\n";
char *text6="Text for file #2...\n";
fname=strdup(argv[1]);
strcat(fname,"file1.fil");
if((f1=fopen(fname,"wt"))==NULL)
printf("%s: %s", fname, trouble);
fname=strdup(argv[1]);
strcat(fname,"file1.hnd");
fh1=open(fname,O_RDWR|O_CREAT|O_TRUNC|O_TEXT,S_IWRITE|S_IREAD);
if(fh1==-1)
{printf("%s: %s",fname,trouble); exit(1);}
printf("File #1 opened.\n");
printf("%s %s",text1,prompt);
len=strlen(text1);
for(i=0;i<repetition;i++)
{
fprintf(f1,text1);
write(fh1,text1,len);
}
getch();
fname=strdup(argv[1]);
strcat(fname,"file2.fil");
f2=fopen(fname,"wt");
fname=strdup(argv[1]);
strcat(fname,"file2.hnd");
fh2=open(fname,O_RDWR|O_CREAT|O_TRUNC,0200|0400);
if( (f2==NULL)||(fh2==-1))
{printf(trouble); exit(1);}
printf("File #2 opened.\n");
printf("%s %s",text2,prompt);
len=strlen(text2);
for(i=0;i<repetition;i++)
{
fprintf(f2,text2);
write(fh2,text2,len);
}
getch();
fname=strdup(argv[1]);
strcat(fname,"file3.fil");
f3=fopen(fname,"wt");
fname=strdup(argv[1]);
strcat(fname,"file3.hnd");
fh3=open(fname,O_RDWR|O_CREAT|O_TRUNC,0200|0400);
if( (f3==NULL)||(fh3==-1))
{printf(trouble); exit(1);}
printf("File #3 opened.\n");
printf("%s %s",text3,prompt);
len=strlen(text3);
for(i=0;i<repetition;i++)
{
fprintf(f3,text3);
write(fh3,text3,len);
}
getch();
printf("%s %s",text4,prompt);
len=strlen(text4);
for(i=0;i<repetition;i++)
{
fprintf(f1,text4);
write(fh1,text4,len);
}
getch();
if(fclose(f3) || close(fh3))
{printf("Can't close file #3???\n");
exit(1);}
remove(fname);
fname=strdup(argv[1]);
strcat(fname,"file3.fil");
remove(fname);
printf("%s %s","File #3 deleted.\n",prompt);
printf("%s %s",text5,prompt);
len=strlen(text5);
for(i=0;i<repetition;i++)
{
fprintf(f1,text5);
write(fh1,text5,len);
}
getch();
printf("%s %s",text6,prompt);
len=strlen(text6);
for(i=0;i<repetition;i++)
{
fprintf(f2,text6);
write(fh2,text6,len);
}
getch();
printf(" Good bye!!!\n");
fcloseall();
close(fh1);
close(fh2);
return(0);
}